package cloning.cci4.ch1;

/*
 * Write an algorithm such that if an element in an MxN matrix is 0, 
 * its entire row and column is set to 0.
 * 
 * CHANGED to search min value in matrix
 * 
 */

public class Task_1_7
{

	public static void main(String[] args)
	{
//		int[][] matrix = new int[3][3];
		int[][] matrix = new int[2][2];
		int generator = 0;
		
		for (int i = 0; i < matrix.length; i++)
		{
			for (int j = 0; j < matrix.length; j++)
			{
				matrix[i][j] = generator;
				generator++;
			}
		}
		
		printMatrix(matrix);
		
		System.out.println("Max element is " + getMaxElement(matrix));
		
	}
	
	private static int getMaxElement(int[][] matrix)
	{
		int result = matrix[0][0];
		
		for (int i = 0; i < matrix.length; i++)
		{
			for (int j = 0; j < matrix.length; j++)
			{
				if (matrix[i][j] > result)
				{
					result = matrix[i][j]; 
				}
			}
			
		
		}
		
		return result;
	}
	
	private static void printMatrix(int[][] matrix)
	{
		
		for (int i = 0; i < matrix.length; i++)
		{
			for (int j = 0; j < matrix.length; j++)
			{
				System.out.print(matrix[i][j] + " ");
			}
			
			System.out.println("\n");
		}
		
	}
	
}
